<template>
  <ul class="catagtory">
    <li
      @click="liClick(index)"
      :class="{ select: index === currIndex }"
      v-for="(item, index) in catagtoryList"
      :key="item.id"
    >
      {{ item.name }}
    </li>
  </ul>
</template>
<script>
import { mapState, mapMutations } from 'vuex'

export default {
  computed: {
    ...mapState('catagtory', ['catagtoryList', 'currIndex'])
  },
  async created () {
    // 触发actions获取分类数据
    console.log(1)
    await this.$store.dispatch('catagtory/channels')
    console.log(2)
    this.$store.dispatch(
      'list/getList',
      this.$store.state.catagtory.catagtoryList[0].id
    )

    // 123   132
  },
  methods: {
    ...mapMutations('catagtory', ['setCurrIndex']),
    liClick (index) {
      this.setCurrIndex(index)
      this.$store.dispatch(
        'list/getList',
        this.$store.state.catagtory.catagtoryList[index].id
      )
    }
  }
}
</script>
<style></style>
